/*
 * SPDX-License-Identifier: Apache-2.0
 */
package org.hyperledger.fabric.samples.fabFileModel;

import java.util.Objects;

import org.hyperledger.fabric.contract.annotation.DataType;
import org.hyperledger.fabric.contract.annotation.Property;

import com.owlike.genson.annotation.JsonProperty;

@DataType()
public final class FileModel {

    @Property()
    private final String filePath;

    @Property()
    private final String fileMd5;

    @Property()
    private final String owner;

    @Property()
    private final String fileName;

    @Property()
    private final String accessID;

    public String getFilePath() {
        return filePath;
    }

    public String getFileName() {
        return fileName;
    }

    public String getAccessID() {
        return accessID;
    }

    public String getFileMd5() {
        return fileMd5;
    }


    public String getOwner() {
        return owner;
    }

    public FileModel(@JsonProperty("filePath") final String filePath, @JsonProperty("fileMd5") final String fileMd5,
           @JsonProperty("owner") final String owner,@JsonProperty("fileName") final String fileName,
           @JsonProperty("accessID") final String accessID) {
        this.filePath = filePath;
        this.fileMd5 = fileMd5;
        this.owner = owner;
        this.fileName=fileName;
        this.accessID=accessID;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }

        if ((obj == null) || (getClass() != obj.getClass())) {
            return false;
        }

       FileModel other = (FileModel) obj;

        return Objects.deepEquals(new String[] {getFilePath(), getFileMd5(),  getOwner(), getAccessID(), getFileName()},
                new String[] {other.getFilePath(), other.getFileMd5(), other.getOwner(),other.getAccessID(), other.getFileName()});
    }

    @Override
    public int hashCode() {
        return Objects.hash(getFilePath(), getFileMd5(), getOwner(), getAccessID(), getFileName());
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
                + " [fileName=" + fileName + ", filePath=" + filePath + ", fileMd5="
                + fileMd5 + ", owner=" + owner +", accessID=" + accessID + "]";
    }
}
